package com.group3.admin.util;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;

public class JmsUtil {
	
	
	private static ConnectionFactory factory;
	private static String ActiveMQUrl="failover://tcp://127.0.0.1:61616";
	static{
		 factory = new ActiveMQConnectionFactory(ActiveMQUrl);
		System.out.println(factory);
	}
	
	
	public static Connection getConnection(){
		Connection conn = null;
		try {
			conn = factory.createConnection();
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn;
	}
	public static void free(Connection conn,Session session,MessageConsumer consumer)
 {
		try {
			if (conn != null) {

				conn.close();

			}
			if (session != null) {
				session.close();
			}
			if (consumer != null) {
				consumer.close();
			}
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	
	
	
}
